<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'viewAdmin.jsp' starting page</title>
<link href="../css/bootstrap-cerulean.css" rel="stylesheet">
<link href="../css/charisma-app.css" rel="stylesheet">
<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}
</style>
	<script src="http://lib.sinaapp.com/js/jquery/2.2.4/jquery-2.2.4.min.js"></script>
	<script src="../js/common/public.js"></script>
	<script src="../js/base64.js"></script>
	<script type="text/javascript">
		$(document).ready(function () {
			var urlMsg  = parseUrl(window.location.search);
			if (urlMsg.token!=null){
				var token = decode(urlMsg.token);
			}
			var html = $.ajax({
				type: "GET",
				url: "http://localhost:1068/admin/class/findAllClass?token="+token,
				async: false
			}).responseText;
			var result = eval('(' + html + ')');
			if (result.code!=200){
				alert(result.msg)
			}else {
				for (index in result.data){
					addClassListTable(result.data[index].id,
							result.data[index].classNumber,
							result.data[index].className,
							result.data[index].monitor,
							result.data[index].score,);
					$('#classScoreDetails'+ result.data[index].id+'').attr('href','classScoreList.html?token='+urlMsg.token+'&classNumber='+result.data[index].classNumber);
					$('#editClassInfo'+ result.data[index].id+'').attr('href','editClass.html?token='+urlMsg.token+'&classNumber='+result.data[index].classNumber);
					$('#addClassScore'+ result.data[index].id+'').attr('href','addClassScore.html?token='+urlMsg.token+'&classNumber='+result.data[index].classNumber);
				}
			}

		});

		function addClassListTable(id,classNumber,className,monitor,score) {
			$("#classList tbody").append("<tr class='odd'>" +
					"<td class=' sorting_1'>"+classNumber+"</td>" +
					"<td class='center '>"+className+"</td>" +
					"<td class='center '>"+monitor+"</td>" +
					"<td class='center '>"+score+"</td>" +
					"<td class='center '>" +
					"<a id='classScoreDetails"+id+"' class='btn btn-success' href=''>" +
					"<i class='icon-zoom-in icon-white'></i>" +
					"量化详细" +
					"</a>" +
					"<a id='editClassInfo"+id+"' class='btn btn-info' href=''>" +
					"<i class='icon-edit icon-white'></i>  " +
					"编辑信息" +
					"</a>" +
					"<a id='deleteClassScore"+id+"' class='btn btn-danger' href='javascript:void(0);' onclick='deleteClass(classNumber="+classNumber+",this);'>" +
					"<i class='icon-trash icon-white'></i> " +
					"删除班级" +
					"</a>" +
					"<a id='addClassScore"+id+"' class='btn btn-info' href=''>" +
					"<i class='icon-edit icon-white'></i>  " +
					"添加量化" +
					"</a>" +
					"</td>" +
					"</tr>");

		}
		function deleteClass(classNumber,a) {
			if(window.confirm('删除班级会删除该班级下所有学生，删除操作不可逆，请确认！')){
				var urlMsg = parseUrl(window.location.search);
				$("#token").val(urlMsg.token);
				if (urlMsg.token != null) {
					var token = decode(urlMsg.token);
					token=token.substring(0,token.length-1);
				}
				var html = $.ajax({
					type: "DELETE",
					url: "http://localhost:1068/admin/class/deleteClass?token="+token+"&classNumber="+classNumber,
					async: false
				}).responseText;
				var result = eval('(' + html + ')');
				if (result.code != 200) {
					alert(result.msg)
				} else {
					alert("删除成功！")
					$(a).parent().parent().remove();
				}
			}else{
				return false;
			}
		}
	</script>
</head>

<body>
	<div class="container-fluid"
		style="padding-left:0px;padding-right:2px;">
		<div class="row-fluid">
			<div id="content" class="span10" style="width:100%;">
				<div class="row-fluid sortable">
					<div class="box span12">
						<div class="box-header well">
							<h2>
								<i class="icon-user"></i>班级列表
							</h2>
						</div>
						<div class="box-content">
							<div id="DataTables_Table_0_wrapper" class="dataTables_wrapper">
								
								<table
									class="table table-striped table-bordered bootstrap-datatable datatable dataTable"
									id="classList">
									<thead>
										  <tr>
										  <th class="sorting_asc"   rowspan="1" colspan="1"  style="width: 15%">班级代号</th>
										  <th class="sorting"   rowspan="1" colspan="1"  style="width: 25%">班级名称</th>
										  <th class="sorting"   rowspan="1" colspan="1"  style="width: 10%">班长姓名</th>
										  <th class="sorting"   rowspan="1" colspan="1"  style="width: 10%">量化总分</th>
										  <th class="sorting"   rowspan="1" colspan="1"  style="width: 40%">操作</th>
										  </tr>
									 </thead>

									<tbody>

									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

</body>
</html>
